/*
    This file is part of Titan.

    Titan is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as 
    published by the Free Software Foundation, either version 3 of 
    the License, or (at your option) any later version.

    Titan is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Titan. If not, see <http://www.gnu.org/licenses/>.
*/

package titan.mobile;

import javax.bluetooth.RemoteDevice;

/*
 * BTSearch.java
 * Panel for Bluetooth Service Discovery
 * Created on 28. Juli 2008, 15:23
 */



/**
 *  
 * @author Mirco Rossi <mrossi@ife.ee.ethz.ch>
 */
public class BTSearchServicesPanel extends java.awt.Panel {

    private boolean m_discoveryStarted;
    public int m_deviceSelection;
    public int m_serviceSelection;
    
    /** Creates new form BTSearch */
    public BTSearchServicesPanel(int num) {
        initComponents();
        label1.setText("Services of Device: "+ TitanMobile.singleton.getBTChoiceAddress(num)); 
        m_deviceSelection=num;
        startServiceDiscovery();
    }
    

    
    public void discoveryStoped(){
        m_discoveryStarted=false;
        
    }
    


private void startServiceDiscovery() {
                m_discoveryStarted=true;
                BTList.removeAll();
		TitanMobile.startServiceDiscovery(m_deviceSelection);
    }


public void appendBT(String s1){
    BTList.add(s1);
}

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        label1 = new java.awt.Label();
        BTList = new java.awt.List();

        BTList.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                BTListItemStateChanged(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, BTList, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, label1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(label1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(BTList, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

private void BTListItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_BTListItemStateChanged
 if(BTList.getSelectedIndex()>-1){   
     //TitanMobile.setBTChoice(BTList.getSelectedIndex());
     m_serviceSelection=BTList.getSelectedIndex();
     TitanMobile.singleton.getGUI().enableNext(true);
 } else{
     TitanMobile.singleton.getGUI().enableNext(false);
 }
}//GEN-LAST:event_BTListItemStateChanged


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.awt.List BTList;
    private java.awt.Label label1;
    // End of variables declaration//GEN-END:variables

}
